<?php

namespace App\Models;

use App\Models\Model;
use Illuminate\Support\Str;

class SUserModel extends Model
{
    protected $table = 's_user';
    protected $fillable = [
        'GUID','ORGGUID','SHARENO','BELONG','CREATEDATE','CREATENAME',
        'NAME','CODE','MOBILEPHONE','PASSWORD','CONTACTSEX','ISDISTRIBUTOR',
    ];
    protected $selects = [
        'GUID','ORGGUID','SHARENO','BELONG','NAME','CODE','MOBILEPHONE','ISDISTRIBUTOR',
    ];

    /**
     * 获取要查询的字段
     */

    /**
     * 根据code获取个人信息
     *
     * @var string
     */
    public function getDetailForCode($employeeCode)
    {
        return $this->select($this->selects)
            ->where([
                'CODE'=>$employeeCode
            ])
            ->first();
    }

    /**
     * 创建员工
     */
    public function createEmployee($employeeDetail,$organizationDetail)
    {
        $guid = (string) Str::uuid();
        $data = [
            'GUID'=>$guid,
            'ORGGUID'=>$organizationDetail->GUID,
            'SHARENO'=>Str::random(6),
            'BELONG'=>'1',
            'CREATEDATE'=>date("Y-m-d H:i:s"),
            'CREATENAME'=>'药店掌柜自动创建',
            'NAME'=>$employeeDetail['employeeName'],
            'CODE'=>$employeeDetail['employeeCode'],
            'MOBILEPHONE'=>$employeeDetail['phone'],
            'PASSWORD'=>md5('000000'),
            'CONTACTSEX'=>$employeeDetail['sex'],
            'ISDISTRIBUTOR'=>'1',
        ];
        return $this->create($data);
    }

}